﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbLayerStateManager : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbLayerStateManager(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbLayerStateManager_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbLayerStateManager obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbLayerStateManager()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbLayerStateManager(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdDbLayerStateManager cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbLayerStateManager_cast(OdRxObject.getCPtr(pObj));
			OdDbLayerStateManager result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbLayerStateManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbLayerStateManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbLayerStateManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbLayerStateManager_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbLayerStateManager_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbLayerStateManager_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbLayerStateManager createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbLayerStateManager_createObject();
			OdDbLayerStateManager result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbLayerStateManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbLayerStateManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbLayerStateManager)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool addReactor(OdDbLayerStateManagerReactor pReactor)
		{
			bool result = TD_DbPINVOKE.OdDbLayerStateManager_addReactor(this.swigCPtr, OdDbLayerStateManagerReactor.getCPtr(pReactor));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool removeReactor(OdDbLayerStateManagerReactor pReactor)
		{
			bool result = TD_DbPINVOKE.OdDbLayerStateManager_removeReactor(this.swigCPtr, OdDbLayerStateManagerReactor.getCPtr(pReactor));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbObjectId layerStatesDictionaryId(bool bCreateIfNotPresent)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr cPtr = TD_DbPINVOKE.OdDbLayerStateManager_layerStatesDictionaryId__SWIG_0(this.swigCPtr, bCreateIfNotPresent);
			OdDbObjectId result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbObjectId(cPtr, true));
				result = new OdDbObjectId(cPtr, false);
			}
			else
			{
				result = new OdDbObjectId(cPtr, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbObjectId layerStatesDictionaryId()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr cPtr = TD_DbPINVOKE.OdDbLayerStateManager_layerStatesDictionaryId__SWIG_1(this.swigCPtr);
			OdDbObjectId result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject(new OdDbObjectId(cPtr, true));
				result = new OdDbObjectId(cPtr, false);
			}
			else
			{
				result = new OdDbObjectId(cPtr, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool hasLayerState(string sName)
		{
			bool result = TD_DbPINVOKE.OdDbLayerStateManager_hasLayerState(this.swigCPtr, sName);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult saveLayerState(string sName, OdDbLayerStateManager.LayerStateMask mask)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_saveLayerState__SWIG_0(this.swigCPtr, sName, (int)mask);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult restoreLayerState(string sName)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_restoreLayerState__SWIG_0(this.swigCPtr, sName);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setLayerStateMask(string sName, OdDbLayerStateManager.LayerStateMask mask)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_setLayerStateMask(this.swigCPtr, sName, (int)mask);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult getLayerStateMask(string sName, SWIGTYPE_p_OdDbLayerStateManager__LayerStateMask returnMask)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_getLayerStateMask(this.swigCPtr, sName, SWIGTYPE_p_OdDbLayerStateManager__LayerStateMask.getCPtr(returnMask));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult deleteLayerState(string sName)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_deleteLayerState(this.swigCPtr, sName);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult renameLayerState(string sName, string sNewName)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_renameLayerState(this.swigCPtr, sName, sNewName);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult importLayerState(OdStreamBuf pStreamBuf)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_importLayerState__SWIG_0(this.swigCPtr, OdStreamBuf.getCPtr(pStreamBuf));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult importLayerState(OdStreamBuf pStreamBuf, ref string sName)
		{
			IntPtr intPtr = Marshal.StringToCoTaskMemUni(sName);
			IntPtr value = intPtr;
			OdResult result;
			try
			{
				OdResult odResult = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_importLayerState__SWIG_1(this.swigCPtr, OdStreamBuf.getCPtr(pStreamBuf), ref intPtr);
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
				result = odResult;
			}
			finally
			{
				if (intPtr != value)
				{
					sName = Marshal.PtrToStringUni(intPtr);
				}
			}
			return result;
		}

		public OdResult exportLayerState(string sNameToExport, OdStreamBuf pStreamBuf)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_exportLayerState(this.swigCPtr, sNameToExport, OdStreamBuf.getCPtr(pStreamBuf));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult saveLayerState(string sName, OdDbLayerStateManager.LayerStateMask mask, OdDbObjectId idVp)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_saveLayerState__SWIG_1(this.swigCPtr, sName, (int)mask, OdDbObjectId.getCPtr(idVp));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult restoreLayerState(string sName, OdDbObjectId idVp, int nRestoreFlags, SWIGTYPE_p_OdDbLayerStateManager__LayerStateMask pClientMask)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_restoreLayerState__SWIG_1(this.swigCPtr, sName, OdDbObjectId.getCPtr(idVp), nRestoreFlags, SWIGTYPE_p_OdDbLayerStateManager__LayerStateMask.getCPtr(pClientMask));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult restoreLayerState(string sName, OdDbObjectId idVp, int nRestoreFlags)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_restoreLayerState__SWIG_2(this.swigCPtr, sName, OdDbObjectId.getCPtr(idVp), nRestoreFlags);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult restoreLayerState(string sName, OdDbObjectId idVp)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_restoreLayerState__SWIG_3(this.swigCPtr, sName, OdDbObjectId.getCPtr(idVp));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult setLayerStateDescription(string sName, string sDesc)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_setLayerStateDescription(this.swigCPtr, sName, sDesc);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult getLayerStateDescription(string sName, ref string sDesc)
		{
			IntPtr intPtr = Marshal.StringToCoTaskMemUni(sDesc);
			IntPtr value = intPtr;
			OdResult result;
			try
			{
				OdResult odResult = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_getLayerStateDescription(this.swigCPtr, sName, ref intPtr);
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
				result = odResult;
			}
			finally
			{
				if (intPtr != value)
				{
					sDesc = Marshal.PtrToStringUni(intPtr);
				}
			}
			return result;
		}

		public bool layerStateHasViewportData(string sName)
		{
			bool result = TD_DbPINVOKE.OdDbLayerStateManager_layerStateHasViewportData(this.swigCPtr, sName);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult importLayerStateFromDb(string pStateName, OdDbDatabase pDb)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_importLayerStateFromDb(this.swigCPtr, pStateName, OdDbDatabase.getCPtr(pDb));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult getLayerStateNames(OdStringArray lsArray, bool bIncludeHidden, bool bIncludeXref)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_getLayerStateNames__SWIG_0(this.swigCPtr, OdStringArray.getCPtr(lsArray), bIncludeHidden, bIncludeXref);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult getLayerStateNames(OdStringArray lsArray, bool bIncludeHidden)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_getLayerStateNames__SWIG_1(this.swigCPtr, OdStringArray.getCPtr(lsArray), bIncludeHidden);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult getLayerStateNames(OdStringArray lsArray)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_getLayerStateNames__SWIG_2(this.swigCPtr, OdStringArray.getCPtr(lsArray));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult getLastRestoredLayerState(ref string sName, OdDbObjectId restoredLSId)
		{
			IntPtr intPtr = Marshal.StringToCoTaskMemUni(sName);
			IntPtr value = intPtr;
			OdResult result;
			try
			{
				OdResult odResult = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_getLastRestoredLayerState(this.swigCPtr, ref intPtr, OdDbObjectId.getCPtr(restoredLSId));
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
				result = odResult;
			}
			finally
			{
				if (intPtr != value)
				{
					sName = Marshal.PtrToStringUni(intPtr);
				}
			}
			return result;
		}

		public OdResult getLayerStateLayers(OdStringArray layerArray, string sName, bool bInvert)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_getLayerStateLayers__SWIG_0(this.swigCPtr, OdStringArray.getCPtr(layerArray), sName, bInvert);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult getLayerStateLayers(OdStringArray layerArray, string sName)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_getLayerStateLayers__SWIG_1(this.swigCPtr, OdStringArray.getCPtr(layerArray), sName);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool compareLayerStateToDb(string sName, OdDbObjectId idVp)
		{
			bool result = TD_DbPINVOKE.OdDbLayerStateManager_compareLayerStateToDb(this.swigCPtr, sName, OdDbObjectId.getCPtr(idVp));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult addLayerStateLayers(string sName, OdDbObjectIdArray layerIds)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_addLayerStateLayers(this.swigCPtr, sName, OdDbObjectIdArray.getCPtr(layerIds));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdResult removeLayerStateLayers(string sName, OdStringArray layerNames)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbLayerStateManager_removeLayerStateLayers(this.swigCPtr, sName, OdStringArray.getCPtr(layerNames));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool isDependentLayerState(string sName)
		{
			bool result = TD_DbPINVOKE.OdDbLayerStateManager_isDependentLayerState(this.swigCPtr, sName);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public OdDbDatabase getDatabase()
		{
			OdDbDatabase result = (OdDbDatabase)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbLayerStateManager_getDatabase(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public const int kUndefDoNothing = 0;

		public const int kUndefTurnOff = 1;

		public const int kUndefFreeze = 2;

		public const int kRestoreAsOverrides = 4;

		private object locker = new object();

		private HandleRef swigCPtr;

		[Flags]
		public enum LayerStateMask
		{
			kNone = 0,
			kOn = 1,
			kFrozen = 2,
			kLocked = 4,
			kPlot = 8,
			kNewViewport = 16,
			kColor = 32,
			kLineType = 64,
			kLineWeight = 128,
			kPlotStyle = 256,
			kCurrentViewport = 512,
			kTransparency = 1024,
			kAll = 2047,
			kStateIsHidden = 32768,
			kLastRestored = 65536,
			kDecomposition = 133119
		}
	}
}
